/*
 * This file is part of the OdinMS Maple Story Server
 * Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
 *                    Matthias Butz <matze@odinms.de>
 *                    Jan Christian Meyer <vimes@odinms.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation. You may not use, modify
 * or distribute this program under any other version of the
 * GNU Affero General Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 Bell (NLC Dude)
**/

var status = -1;
var cost = 5000;

function start() {
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
		return;
	} else if (mode == 1) {
		status++;
	} else {
		if (cm.getPlayer().getMapId() == 600010004 || cm.getPlayer().getMapId() == 600010002) {
			status--;
		} else {
			cm.sendOk("Okay then. Tell me if you change your mind.");
			cm.dispose();
			return;
		}
	}
	if (status == 0) {
		if (cm.getPlayer().getMapId() == 600010004 || cm.getPlayer().getMapId() == 600010002) {
			status = 10;
			cm.sendYesNo("Do you want to leave the waiting room? You can, but the ticket is NOT refundable. Are you sure you still want to leave this room?");
		} else {
			city = "#r(AN ERROR HAS OCCURED)#k";
			if (cm.getPlayer().getMapId() == 103000100) {
				city = "New Leaf City";
			} else if (cm.getPlayer().getMapId() == 600010001) {
				city = "Kerning City";
			}
			cm.sendYesNo("Hi there, I sell tickets to "+city+". In order to board the subway, you must have a ticket. Would you like to buy a ticket for "+cost+" mesos?");
		}
	} else if (status == 1) {
		var itemid;
		if (cm.getPlayer().getMapId() == 103000100) {
			itemid = 4031711;
		} else {
			itemid = 4031713;
		}
		if(!cm.canHold(itemid) || cm.getPlayer().getMeso() < cost) {
			cm.sendOk("I don't think you have enough meso or empty slot in your ETC inventory. Please check and talk to me again.");
		} else {
			if (cm.getPlayer().getMapId() == 103000100) {
				cm.sendOk("Here you go! \r\nThe ticket gate is on the far right. Double click on it and select \"New Leaf City (Normal)\" to go to the station platform. Do NOT enter through the portal.");
			} else if (cm.getPlayer().getMapId() == 600010001) {
				cm.sendOk("Here you go! \r\nThe ticket gate is to my left. Double click on it to get on the subway. You may have to wait a bit for the train to come, so be patient!~");
			}
			cm.gainMeso(-cost);
			cm.gainItem(itemid, 1);
		}
		cm.dispose();
	} else if (status == 9) {
		cm.sendOk("Please be a little more patient. The train will be leaving in a few moments. Thank you.");
		cm.dispose();
	} else if (status == 11) {
		if (cm.getPlayer().getMapId() == 600010002) {
			cm.warp(600010001);
		} else {
			cm.warp(103000100);
		}
		cm.dispose();
	} else {
		cm.sendOk("Okay then. Tell me if you change your mind.");
		cm.dispose();
	}
}
